import axios from '@/api'


export interface IArea {
  s_up_id: string;
  s_a_id: string;
  s_a_nam: string;
  children?: Array<IArea>
}
export interface IGetAreaList {
  request: {
    usr_sfz: string;
    usr_psw: string;
  },
  response: Array<IArea>
}

class PublicServices {
  constructor() { }

  /**
   * 获取地区列表
   *
   * @returns
   * @memberof AreaServices
   */
  async getAreaList(data: { s_a_id?: string }) {
    const res = await axios.post<unknown, Api.ResponseOptions<IGetAreaList['response']>>('/btpub/pub/get-area-list', data)
    return res
  }

  /**
   * 获取下级行政区数据
   *
   * @param {Pick<IArea, 's_a_id'>} data
   * @returns
   * @memberof AreaServices
   */
  async getAreaLazy(data: Pick<IArea, 's_a_id'>) {
    const res = await axios.post<unknown, Api.ResponseOptions<IGetAreaList['response']>>('/btpub/pub/get-next-area', data)
    res.data = res.data.map(item => {
      if (item.s_a_nam) {
        return { ...item, hasChild: true }
      }
      return item
    })
    return res
  }

  /**
   * 编辑行政区
   *
   * @param {IArea} data
   * @returns
   * @memberof AreaServices
   */
  async editArea(data: IArea) {
    return await axios.post<unknown, Api.ResponseOptions>('/btsys/area/edit-area', data)
  }

  /**
   * 删除行政区
   *
   * @param {Pick<IArea, 's_a_id'>} data
   * @returns
   * @memberof AreaServices
   */
  async deleteArea(data: Pick<IArea, 's_a_id'>) {
    return await axios.post<unknown, Api.ResponseOptions>('/btsys/area/del-area', data)
  }

  /**
   * 获取统计数据
   *
   * @returns
   * @memberof PublicServices
   */
  getCount() {
    return axios.post<unknown, Api.ResponseOptions>('/btsys/pub/get-count')
  }

  /**
   * 获取execl上传进度
   *
   * @returns
   * @memberof PublicServices
   */
  getUploadProcess(data: Api.PageOptions & { type: string }) {
    return axios.post<unknown, Api.ResponseOptions>('/btsys/pub/get-upload-log', data)
  }

  /**
   * 检查当前区域是否锁定
   *
   * @param {{ s_a_id: string }} data
   * @returns
   * @memberof PublicServices
   */
  checkAreaLock(data: { s_a_id: string }) {
    return axios.post<unknown, Api.ResponseOptions>('/btpub/pub/check-area-lock', data)
  }
  
}

export const publicServices = new PublicServices()

export default PublicServices
